package com.ruoyi.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.client.Channel;
import com.ruoyi.pojo.Investment;
import com.ruoyi.pojo.Uesr;
import com.ruoyi.service.InvestmentService;
import com.ruoyi.service.UesrService;
import com.ruoyi.utils.DuanxinUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

@Configuration
public class RabbitConfig {
    @Autowired
    private InvestmentService investmentService;

    @Autowired
    private UesrService usrService;

//    @RabbitListener(queues = "deadQueue")
//    public void rabbitUpdate(Integer iid, Message message, Channel channel) throws IOException {
//        QueryWrapper<Investment> investmentQueryWrapper = new QueryWrapper<>();
//        investmentQueryWrapper.eq("iid",iid);
//        List<Investment> investmentList = investmentService.list(investmentQueryWrapper);
//        Investment investment = investmentList.get(0);
//        BigDecimal b1 = new BigDecimal("0");
//        if (b1.subtract(investment.getImoney()).compareTo(BigDecimal.ZERO) != 1){
//            QueryWrapper<Uesr> uesrQueryWrapper = new QueryWrapper<>();
//            uesrQueryWrapper.eq("uid",investment.getUid());
//            List<Uesr> list = usrService.list(uesrQueryWrapper);
//            Uesr uesr = list.get(0);
//            DuanxinUtils.sendDuanxin(uesr.getCellphonenumber(),"6666");
//            investmentService.remove(investmentQueryWrapper);
//        }
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }

    @RabbitListener(queues = "user")
    public void userRabbit(Integer iid, Message message, Channel channel) throws IOException {
        System.out.println(iid);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
